<div class="users view row">
    <div class="actions col-md-2">
        <h2><kbd>Actions</kbd></h2>
        <hr/>
        <ul class="nav nav-stacked">
            <?php if ($userId == $user['User']['id']): ?>
                <li><?php echo $this->Html->link(__('Edit User'), array('action' => 'edit', $user['User']['id'])); ?> </li>
                <li><?php echo $this->Form->postLink(__('Delete User'), array('action' => 'delete', $user['User']['id']), null, __('Are you sure you want to delete # %s?', $user['User']['id'])); ?> </li>
            <?php endif; ?>
            <li><?php echo $this->Html->link(__('List Users'), array('action' => 'index')); ?> </li>
            <li><?php echo $this->Html->link(__('New User'), array('action' => 'add')); ?> </li>
            <li><?php echo $this->Html->link(__('List Categories'), array('controller' => 'categories', 'action' => 'index')); ?> </li>
            <li><?php echo $this->Html->link(__('New Category'), array('controller' => 'categories', 'action' => 'add')); ?> </li>
            <li><?php echo $this->Html->link(__('List Wallets'), array('controller' => 'wallets', 'action' => 'index')); ?> </li>
            <li><?php echo $this->Html->link(__('New Wallet'), array('controller' => 'wallets', 'action' => 'add')); ?> </li>
        </ul>
    </div>
    <div class="col-md-10">

        <h2><kbd><?php echo __('User'); ?></kbd></h2>
        <hr/>
        <table class="table table-bordered">
            <tr class="success">
                <td>Id</td>
                <td>User Name</td>
                <td>Email</td>
                <td>Created</td>
                <td>Updated</td>
                <td>Last Access</td>
            </tr>
            <tr>
                <td><?php echo h($user['User']['id']) ?></td>
                <td><?php echo $this->Html->link($user['User']['username'], array('controller' => 'profiles', 'action' => 'view', $user['User']['id'])); ?></td>
                <td><?php echo h($user['User']['email']) ?></td>
                <td><?php echo h($user['User']['created']) ?></td>
                <td><?php echo h($user['User']['updated']) ?></td>
                <td><?php echo h($user['User']['last_access']) ?></td>
            </tr>
        </table>

        <div class="related">
            <h3><?php echo __('Related Categories'); ?></h3>
            <hr/>
            <?php if (!empty($user['Category'])): ?>
                <table class="table table-bordered">
                    <tr class="success">
                        <th><?php echo __('Name'); ?></th>
                        <th><?php echo __('Description'); ?></th>
                        <th><?php echo __('Parent'); ?></th>
                        <th><?php echo __('Type'); ?></th>

                        <th class="actions"><?php echo __('Actions'); ?></th>
                    </tr>
                    <?php foreach ($user['Category'] as $category): ?>
                        <tr>
                            <td><?php echo $category['name']; ?></td>
                            <td><?php echo $category['description']; ?></td>

                            <td>
                                <?php
                                $parent = $category['parent_id'];
                                if ($parent !== null) {
                                    for ($i = 0; $i < count($user['Category']); $i++) {
                                        if ($parent == $user['Category'][$i]['id']) {
                                            echo $user['Category'][$i]['name'];
                                        }
                                    }
                                }
                                ?>
                            </td>
                            <td><?php echo $category['type'] == 1 ? "Earned From" : "Spent On"; ?></td>
                            <td class="actions">
                                <?php echo $this->Html->link(__('View'), array('controller' => 'categories', 'action' => 'view', $category['id']), array('class' => 'btn-sm btn-info')); ?>
                                <?php if ($userId == $category['user_id']): ?>
                                    <?php echo $this->Html->link(__('Edit'), array('controller' => 'categories', 'action' => 'edit', $category['id']), array('class' => 'btn-sm btn-warning')); ?>
                                    <?php echo $this->Form->postLink(__('Delete'), array('controller' => 'categories', 'action' => 'delete', $category['id']), array('class' => 'btn-sm btn-danger'), __('Are you sure you want to delete # %s?', $category['id'])); ?>
                                <?php endif; ?>
                            </td>

                        </tr>
                    <?php endforeach; ?>
                </table>
            <?php endif; ?>

            <div class="actions">
                <ul>
                    <li class="btn"><?php echo $this->Html->link(__('New Category'), array('controller' => 'categories', 'action' => 'add'), array('class' => 'btn btn-success')); ?> </li>
                </ul>
            </div>
        </div>
        <div class="related">
            <h3><?php echo __('Related Wallets'); ?></h3>
            <hr/>
            <?php if (!empty($user['Wallet'])): ?>
                <table class="table table-bordered">
                    <tr class="success">
                        <th><?php echo __('Id'); ?></th>
                        <th><?php echo __('User Id'); ?></th>
                        <th><?php echo __('Name'); ?></th>
                        <th><?php echo __('Current Money'); ?></th>
                        <th><?php echo __('Created'); ?></th>
                        <th><?php echo __('Updated'); ?></th>

                        <th class="actions"><?php echo __('Actions'); ?></th>

                    </tr>
                    <?php foreach ($user['Wallet'] as $wallet): ?>
                        <tr>
                            <td><?php echo $wallet['id']; ?></td>
                            <td><?php echo $wallet['user_id']; ?></td>
                            <td><?php echo $wallet['name']; ?></td>
                            <td><?php echo number_format($wallet['current_money']) . " VND"; ?></td>
                            <td><?php echo $wallet['created']; ?></td>
                            <td><?php echo $wallet['updated']; ?></td>

                            <td class="actions">
                                <?php echo $this->Html->link(__('View'), array('controller' => 'wallets', 'action' => 'view', $wallet['id']), array('class' => 'btn-sm btn-info')); ?>
                                <?php if ($userId == $wallet['user_id']): ?>
                                    <?php echo $this->Html->link(__('Edit'), array('controller' => 'wallets', 'action' => 'edit', $wallet['id']), array('class' => 'btn-sm btn-warning')); ?>
                                    <?php echo $this->Form->postLink(__('Delete'), array('controller' => 'wallets', 'action' => 'delete', $wallet['id']), array('class' => 'btn-sm btn-danger'), __('Are you sure you want to delete # %s?', $wallet['id'])); ?>
                                <?php endif; ?>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                </table>
            <?php endif; ?>

            <div class="actions">
                <ul>
                    <li class="btn"><?php echo $this->Html->link(__('New Wallet'), array('controller' => 'wallets', 'action' => 'add'), array('class' => 'btn btn-success')); ?> </li>
                </ul>
            </div>
        </div>
    </div>
